package ljt.music.ui.main;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.ljq.mvpframework.presenter.BaseMvpPresenter;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author jiangtao
 */
public class MainActivityPresenter extends BaseMvpPresenter<MainActivityView> {

    private final MainActivityModel mMainActivityModel;

    public MainActivityPresenter() {
        this.mMainActivityModel = new MainActivityModel();
    }

    @Override
    public void onCreatePresenter(@Nullable Bundle savedState) {
        super.onCreatePresenter(savedState);
        if(savedState != null){
            Log.e("perfect-mvp","MainActivityPresenter  onCreatePresenter 测试  = " + savedState.getString("test2") );
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Log.e("perfect-mvp","MainActivityPresenter  onSaveInstanceState 测试 " );
        outState.putString("test2","test_save2");
    }

    @Override
    public void onDestroyPresenter() {
        super.onDestroyPresenter();
    }

    public void request(final String cityId){
        Log.e("perfect-mvp","点击事件 P ");
        if(getMvpView() != null){
            getMvpView().requestLoading();
        }

        mMainActivityModel.request(cityId, new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {

            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        });

//        //模拟网络延迟，可以显示出加载中
//        new Handler().postDelayed(new Runnable() {
//            @Override
//            public void run() {
//
//            }
//        },1000);
    }

    public void interruptHttp(){
        mMainActivityModel.interruptHttp();
    }
}
